package org.hiucung.lib_base.event

import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import java.util.*

/**
 *
 * @author : its-kicc
 * @date : 2021/10/21 14:59
 * EvenBus事件管理
 *
 * kotlin的object关键字相当于java中的单例
 */
object EventManager {

    //注册
    fun register(subscriber : Any){
        EventBus.getDefault().register(subscriber)
    }

    //解绑
    fun unRegister(subscriber : Any){
        EventBus.getDefault().unregister(subscriber)
    }

    //发送事件类，基本上用不到
    private fun post(event: MessageEvent){
        EventBus.getDefault().post(event)
    }

    //-----------------------------------------对外开放的方法------------------------

    //发送类型，根据数字去定义传达的命令
    fun post(type: Int){
        post(MessageEvent(type))
    }

    //发送类型，携带字符串
    fun post(type: Int, string: String){
        val event = MessageEvent(type)
        event.stringValue = string
        post(event)
    }

    //发送类型，携带整形
    fun post(type: Int, int: Int){
        val event = MessageEvent(type)
        event.intValue = int
        post(event)
    }

    //发送类型，携带布尔值
    fun post(type: Int, boolean: Boolean){
        val event = MessageEvent(type)
        event.booleanValue = boolean
        post(event)
    }
}